import { CourseType, IUserParams, UserInfoType } from "../type/course";
import request from "../utils/request";

export const userLogin = (userObj: IUserParams) => {
  return request.post("login", userObj);
};

//收藏
export interface CollectType extends Partial<CourseType> {
  userid: string;
  courseid: string;
}
export const collectPost = (collectObj: CollectType) => {
  return request.post("classes/ReactCollect", collectObj);
};

//获取收藏
interface CollectConditionType {
  userid: string;
  courseid?: string;
}
export const collectGet = (userid: string, courseid?: string) => {
  let where: CollectConditionType = { userid };
  if (courseid) {
    where.courseid = courseid;
  }
  return request.get("classes/ReactCollect", {
    params: {
      where,
    },
  });
};

// 移除收藏
export const collectDel = (collectId: string) => {
  return request.delete(`classes/ReactCollect/${collectId}`);
};

//更新用户信息
export const userUpdate = (userid: string, info: Partial<UserInfoType>) => {
  return request.put(`users/${userid}`, info);
};
